Microcontroller units (MCU) have been used in the manufacturing and electrical industries for many years. In any microprocessor or microcontroller, there are memory locations (i.e., RAM) that are used to hold intermediate values. Those memory locations can be used to implement a conceptual data container called a “stack.” A stack is a structure that behaves like a linear list for which all insertions and deletions are made at one end of the list. The rules or axioms that specify what a stack is can be stated in terms of three operations, commonly called push, pop, and top. Push adds an item to a stack, pop deletes the most recently added item, and top returns that item, leaving the stack unchanged. A stack is used for a variety of software applications that execute on the microcontroller.
Most microcontrollers have a limited memory resources. The amount of memory resources can be increased through the use of software stacks. A software stack is a method where a set of data locations are used for storing context that is local to one part of a whole computer program. This method allows for efficient RAM usage, because only the portion of a computer program which is currently active consumes RAM space. The software stack is implemented by having a dedicated pointer that indicates the top of the stack. The dedicated pointer is commonly called the stack pointer. Data may be added to, or removed from, the software stack by manipulating the stack pointer. Data in the stack may also be referenced by using “stack-pointer relative addressing” whereby an offset from the stack pointer is used to address data.
FIG. 1 illustrates the use of RAM to create a software stack. Specifically, a portion of the RAM 102 is reserved as a software stack 104. An expanded view of the software stack 104 is illustrated on the right side of FIG. 1. Specifically, the software stack 104 has a stack pointer 150, as well as additional registers that are accessible using an offset from the stack pointer 150. For example, the register 152 that is adjacent to the stack pointer 150 is accessible as stack pointer +1. Similarly, the register adjacent to the register 152 is offset by two from the stack pointer 150. The stack contains ‘n’ registers, with the last register 198 being offset from the stack pointer by the number ‘n’ as illustrated in FIG. 1.
Because many high-level languages are designed in such a way that use of a software stack is necessary, the overall performance of software applications written with a high-level language is dependent upon the microcontroller's ability to process efficiently the stack-relative operations. Fast software stack access and manipulation can improve overall performance. As faster performance for software applications is desired, there is a need, therefore, for decreasing the time needed to access and/or manipulate the software stack.